<?php

///////////////////////////////////////////////////////////////////////////////
/**
 * System requirements:
 * <ul>
 * <li>PHP 5</li>
 * </ul>
 *
 * This library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * The Connector library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * {@link http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License}
 * for more details.
 *
 * @author Per Egil Roksvaag
 * @copyright 2009 Per Egil Roksvaag
 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
 * @package connector
 * @version 2.0.0
 */

///////////////////////////////////////////////////////////////////////////////
/**
 * Exception class for the Connector library 
 * @package connector
 */
class ConnectorException extends Exception
{
	///////////////////////////////////////////////////////////////////////////
	// Error Constants

	const CONNECTION_FAILED = 1010;
	const QUERY_FAILED = 1020;
	const TRANSACTION_FAILED = 1030;
	
	///////////////////////////////////////////////////////////////////////////
	/**
	 * @var array A string table assigning error messages to error codes.
	 */
	static public $table = array
	(
		self::CONNECTION_FAILED => "Database connection failed. %s",
		self::QUERY_FAILED => "SQL query failed. %s\n%s\nParams: %s",
		self::TRANSACTION_FAILED => "SQL transaction failed. %s",
	);

	///////////////////////////////////////////////////////////////////////////
	/**
	 * @param int $code An error code constant
	 * @param array $param An array of values to insert into the error message.
	 * @return ConnectorException
	 */
	public function ConnectorException($code, $param = array())
	{
		$msg = vsprintf(self::$table[$code], $param);
		parent::__construct($msg, $code);
	}

	///////////////////////////////////////////////////////////////////////////
}

?>